class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-01-08",
      revision: "76c02f99c367ba8e27b3c464d60371a149815161"
  version "2022-01-08"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "12bb57ea185cff00b2f5f7d2f2923cbeeef39d9157f016f8d071b9209a6b30d5"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "558b4b76d2a26176799e5d86daf3a8b58679c95638ed3d2186fcf34e1ed632f7"
    sha256 cellar: :any_skip_relocation, monterey:       "b69f47f755127180d1ccd1a5c130ec084a3146639e8138a89f74515826cd146e"
    sha256 cellar: :any_skip_relocation, big_sur:        "a1d6b860e9d58597554e00d09bb20c87d28b25a8cfa5ffcfb5361f5646593da6"
    sha256 cellar: :any_skip_relocation, catalina:       "4323006072652155e7fa6802e5f77543feb04adcd8b27519bb051cde5e340cd9"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "03ac331e43b4806b2b00996b97b766391662232a9a4255a58796183e4afaa85a"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
